package com.testfileupload.uploadimg.design.single;

/**
 * 懒汉式(线程不安全)
 * 实现了懒加载的模式，但是只能在单线程下运行
 */
public class SingleModel3 {
    public static void main(String[] args) {
        Single2 instence = Single2.getInstence();
        Single2 instence1 = Single2.getInstence();
        System.out.println(instence);
        System.out.println(instence1);
        System.out.println(instence.equals(instence1));
        System.out.println(instence == instence1);
    }
}

class Single2 {

    private static Single2 single;

    /**
     * 构造私有化，不能new
     */
    private Single2() {
    }

    /**
     * 提供共有静态方法
     *
     * @return
     */
    public static Single2 getInstence() {
        if (single == null) {
            single = new Single2();
        }
        return single;
    }

}
